package logic

import (
	"context"
	"errors"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type FaseLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFaseLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FaseLoginLogic {
	return &FaseLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 人脸识别登录
func (l *FaseLoginLogic) FaseLogin(in *user.FaseLoginRequest) (*user.FaseLoginResponse, error) {
	if in.Image == "" {
		pkg.Error("图片参数不能为空")
		return nil, errors.New("图片参数不能为空")
	}
	// 检查用户ID是否有效
	//if in.UserId <= 0 {
	//	pkg.Error("用户ID无效")
	//	return nil, errors.New("用户ID无效")
	//}
	face, err := dao.FaceLogin(in.Id, in.Image)
	if err != nil {
		pkg.Error("人脸识别失败", zap.Error(err))
		return nil, err
	}
	return &user.FaseLoginResponse{
		UserId: int64(face),
		Msg:    "人脸识别登录成功",
	}, nil
}
